package module{
	
	import com.greensock.TweenLite;
	
	import component.Image;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class LoginPanel extends Sprite{
		
		public static var instance:LoginPanel = new LoginPanel();
		
		private var button:Sprite;
		
		private var open:Boolean;
		
		public function LoginPanel(){
			
			this.button = addChild(new Sprite()) as Sprite;
			this.button.addEventListener(MouseEvent.CLICK,onClick);
			this.button.buttonMode = true;
			var btnBg:Image = this.button.addChild(new Image()) as Image;
			btnBg.load("resource/ButtonNormal.png",function():void{
				var bg:Image = addChild(new Image()) as Image;
				bg.load("resource/LoginBg.png",function():void{
					bg.x = btnBg.width;
					x = Global.stage.stageWidth - 40;
					y = (Global.stage.stageHeight - height)>>1;
					button.y = height>>1;
				});
			});
		}
		
		private function onClick(e:MouseEvent):void{
			openEffect(!open);
		}
		
		
		private function openEffect(isOpen:Boolean):void{
			this.open = isOpen;
			if(isOpen){
				var targert:Sprite = this;
				var dX:int = (Global.stage.stageWidth - width);
				TweenLite.to(targert,0.6,{x:dX});
			}else{
				TweenLite.to(this,0.7,{x: Global.stage.stageWidth - 40});
			}
		}
		
		
		public function onResize():void{
			this.x = (Global.stage.stageWidth - width);
			this.y = (Global.stage.stageHeight - height)>>1;
		}
		
	}
}